package com.liziing.controller;

import com.google.gson.Gson;
import com.liziing.mapper.CourseMapper;
import com.liziing.pojo.CourseInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@SuppressWarnings("all")
@RestController
public class CourseController {
    Gson gson = new Gson();
    @Autowired
    private CourseMapper courseMapper;
    @GetMapping("/testcourse")
    public String testcourse(){
        List<CourseInformation> courseinformation = courseMapper.selectList(null);
        return gson.toJson(courseinformation);
    }
    @PostMapping("/add")
    public void addCourseInformation(@RequestBody CourseInformation courseInformation){
        courseMapper.insert(courseInformation);
    }
    @PostMapping("/update")
    public void upCourseInformation(@RequestBody CourseInformation courseInformation){
        courseMapper.updateById(courseInformation);
    }
    @PostMapping("/delete")
    public void deleteCourseInformation(@RequestBody CourseInformation courseInformation){
        courseMapper.deleteById(courseInformation);
    }
}
